/*
 * @lc app=leetcode.cn id=38 lang=cpp
 *
 * [38] 外观数列
 */

// @lc code=start
class Solution {
public:
    string countAndSay(int n) {
        string res="1";
        for(int i = 1; i < n ;i++){
            string tem="";
            int cnt=1;
            for(int j = 0; j < res.length() ;){
                while(j+cnt <res.length() && res[j]==res[j+cnt]){cnt++;}
                tem.push_back(cnt+'0');
                tem.push_back(res[j]);
                j +=cnt;
                cnt=1;
            }

            res=tem;

        }
        return res;

    }
};
// @lc code=end

